#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
void solve()
{
    string s;
    cin >> s;
    bool flag = 0;
    vector<ll> ans;
    ll cnt = 0;
    vector<ll> vis(11, 0);
    for (ll i = s.size() - 1; i >= 0;i--)
    {
        int now = s[i] - '0';
        if(now!=0&&(!flag)){
            flag = 1;
            continue;
        }
        if(now==0&&(!flag))
        {
            cnt++;
        }
        if(now!=0)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}
int main()
{
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
